#!/bin/bash
#文件位置
path=
#文件夹名称
folderName=light-control
#配置文件路径
configPath=/config.js
serverName=nginx
dockerName=es_iot_front
dockerImageName=registry.cn-hangzhou.aliyuncs.com/es_report/es_iot_front
echo $dockerName

docker -v

# 检查容器是否已经启动
if [ "$(docker ps -q -f name=$dockerName)" ]; then
    # 如果容器已经启动，则停止容器
    echo "如果容器已经启动,停止容器"
    docker stop $dockerName
fi

# 检查容器是否存在
if [ "$(docker ps -aq -f status=exited -f name=$dockerName)" ]; then
    # 如果容器存在，则删除容器
    echo "如果容器存在,删除容器"
    docker rm $dockerName
fi



# 判断docker image是否存在
if docker images | grep -q $dockerImageName; then
  # 删除docker image
  docker rmi $dockerImageName
  echo "Docker image $dockerImageName has been deleted."
else
  echo "Docker image $dockerImageName does not exist."
fi


#更新镜像
docker login --username=aliyun7229430423 --password=zxcvbnm5306 registry.cn-hangzhou.aliyuncs.com
docker pull $dockerImageName:latest

#启动临时服务
docker run --name  $dockerName -d $dockerImageName


#删除旧项目
cd $path
rm -rf $folderName
#docker内复制最新的文件
docker cp $dockerName:/usr/share/nginx/html $path
#修改文件夹名称
mv html $folderName
#覆盖配置文件
cp -f $configPath $path/$folderName

#删除明细方式
#cd $path/$folderName
#rm -rf 50x.html
#rm -rf assets
#rm -rf favicon
#rm -rf index.html
#rm -rf js
#rm -rf map
#rm -rf title.ico

docker cp $dockerName:/usr/share/nginx/html $path/
docker stop $dockerName
docker rm $dockerName
